package com.ruoyi.order.config;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.order.domain.TbOrder;
import com.ruoyi.order.service.ITbOrderService;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * kafka异步通讯
 *
 * @author 12692
 */
@Component
public class KafkaTowConfig {
    @Resource
    ITbOrderService orderService;
    @KafkaListener(topics = "TableTow")
    public void KafkaTowConfig(String tbOrder){
        ObjectMapper objectMapper = new ObjectMapper();
        TbOrder order = null;
        try {
            order = objectMapper.readValue(tbOrder, TbOrder.class);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        orderService.insertTbOrderOne(order);
    }
}
